Skip to content

Conversation

@AlinaSheyanova
Copy link

No description provided.


@Component.Factory
interface Factory {
fun build(@BindsInstance app: App) : ApplicationComponent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. обычно метод в Factory называют create, build используют в Builder
  2. тут нужно пробросить Сontext, а не App
  3. нужно использовать квалификатор @ApplicationContext, потому что он может быть ActivityContext

import javax.inject.Qualifier

@MainActivityScope
@Component(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это должен быть Subcomponent для ApplicationComponent, а не отдельный компонент


@Component.Factory
interface Factory {
fun build(@BindsInstance appContext: Context,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут не нужно прокидывать и appContext и activity, достаточно будет @MainActivityContext context: Context, соответственно нужно создать @ApplicationContext аннотации:

@Qualifier
annotation class ApplicationContext

class ReceiverViewModel(
class ReceiverViewModel @Inject constructor(
private val state: ColorState,
private val context: Context

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут мы получаем @ApplicationContext

}
}

val MainActivity.Component: MainActivityComponent get() = this.component

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обычно свойства с маленькой буквы MainActivity.сomponent

private val color: ColorSaver,
private val colorGenerator: ColorGenerator,
private val context: Context
@param:MainActivityContext private val context: Context

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут получаем @ActivityContext

annotation class MainActivityContext

@Module
object MainActivityModule {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот модуль будет не нужен

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants